/**
 * 2
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-10-12 下午6:41
 */

#include <iostream>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long n, m, a, b;
        cin >> n >> m >> a >> b;
        if (n < a) {
            cout << 0 << endl;
        } else {
            cout << min((n * b) / a, m) << endl;
        }
    }
    return 0;
}
